package springMVC.controller;

import java.io.UnsupportedEncodingException;
import java.sql.Date;
import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import springMVC.bean.User;

@Controller
public class FirmController {

	 @Autowired
	    private HttpServletRequest request;
	 
	
	//将String类型转化为Data
//	@InitBinder
//	public void initStringToDate(HttpServletRequest servlet,ServletRequestDataBinder binger) {
//		binger.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-mm-dd"), true));
//																																																																																																																																																																																																
//	}
	//显示表单内容
	@RequestMapping(value="/getUserInfo",method=RequestMethod.GET)
	public String getUserInfo() {
		return "userinfo";
	}
	//处理表单
	@RequestMapping(value="/saveUser",method=RequestMethod.POST)
	public String saveUser(User user) {
		try {
			request.setCharacterEncoding("UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
		System.out.println(user.toString());
		System.out.println(request.getCharacterEncoding());
		return "success";
	}
}
